<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/thesame.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/rightCon.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/footer.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/layui/css/modules/layer/default/layer.css}" media="all">
</head>

<body class="layui-layout-body layui-layout-body-scroll">
<div class="layui-body layui-body-bot">
    <!-- 内容主体区域 -->
    <div class="add-title"><span class="mr10px return"><img th:src="@{/static/img/icon_return.png}"></span><span>新建用户</span></div>
    <div class="scroll-box scroll-box-top scroll-box-bot bgWhite box-shadows border-radius1">
        <div class="scroll-box-padding">
            <div class="scroll-box-con">
                <article>
                    <div class="add-title-border">用户管理</div>
                    <div class="form-style form-box form-user-new">
                        <div>
                            <div class="form-title">
                                <label><em class="red">*</em>用户名称：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" id="orgName" maxlength="50" placeholder="请输入">
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label><em class="red">*</em>管理员账号：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" id="userId" maxlength="20" placeholder="请输入">
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label><em class="red">*</em>开始时间：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" placeholder="请输入" readonly id="startTime" class="form-input-time test-item">
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label><em class="red">*</em>到期时间：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" placeholder="请输入" readonly id="overdueTime" class="form-input-time test-item">
                                </p>
                            </div>
                        </div>
                    </div>
                </article>
                <!--  <article>
                      <div class="add-title-border mt20px">可用设备</div>
                      <ul class="facility-ul">
                          <li>21栋大门人脸</li>
                          <li>21栋大门人脸</li>
                          <li>大门人脸</li>
                          <li>研发中心大门人脸</li>
                          <li>21栋大门人脸</li>
                          <li>21栋大门人脸</li>
                          <li>21栋大门人脸</li>
                      </ul>
                  </article>-->
            </div>
        </div>
    </div>
</div>
<div class="layui-footer layui-footer-one">
    <div class="btn-con textCenter">
        <span class="btn-cancel return">取&nbsp;消</span>
        <span class="btn-submit" id="submit">提&nbsp;交</span>
    </div>
</div>
<script src="js/jquery-3.1.1.min.js" th:src="@{/static/js/jquery-3.1.1.min.js}"></script>
<script src="layui/layui.js" th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script src="js/selectColor.js" th:src="@{/static/js/selectColor.js}" charset="utf-8"></script>
<script src="js/selectColor.js" th:src="@{/static/layer/layer.js}" charset="utf-8"></script>
<script>

    $(function () {
        $(".return").on('click', function () {
            window.history.back();
        })

        $("#submit").on('click', function () {
            save();
        })
    });


    function save() {
        var orgName = $("#orgName").val();
        var userId = $("#userId").val();
        var startTime = $("#startTime").val();
        var overdueTime = $("#overdueTime").val();

        if (isNull(orgName)) {
            layer.msg("请输入用户名称")
            return;
        }

        if (isNull(userId)) {
            layer.msg("请输入用户账号")
            return;
        }

        if (isNull(startTime)) {
            layer.msg("请选择开始时间")
            return;
        }

        if (isNull(overdueTime)) {
            layer.msg("请选择结束时间")
            return;
        }

        if (startTime > overdueTime) {
            layer.msg("开始时间不能大于到期时间")
            return;
        }
        var data = {orgName: orgName, userId: userId, startTime: startTime, overdueTime: overdueTime}
        $.ajax({
            url: "../org/addOrgs",
            type: "post",
            async: false,
            dataType: "json",
            data: data,
            success: function (result) {
                if (result.code == 200) {
                    layer.alert("保存成功", function () {
                        window.location.href = "../org/toOrgListPage";
                    })
                } else {
                    layer.msg(result.msg);
                }
            }
        })
    }

    //左侧菜单栏
    layui.use(['element', 'laydate'], function () {
        var element = layui.element;
        var laydate = layui.laydate;
        var now = new Date();
        lay('.test-item').each(function () {
            laydate.render({
                elem: this,
                trigger: 'click',
                /*value: '1989-10-14'*/
                min: now.toLocaleString()
                , type: 'datetime'
            });
        });
    });

    function isNull(value) {
        return value == null || value === "" || value === undefined;
    }
</script>
</body>

</html>
